package com.wei.czz.common.enums.admin.dept;

import com.wei.czz.common.dto.common.NameValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2024-11-10 20:36:13
 * className: BusinessTypeEnum 业务类型枚举类
 * version: 1.0
 * description:
 */
@Getter
@AllArgsConstructor
public enum BusinessTypeEnum {

    ORG(0, "集团内部"),

    COMPANY(1, "公司"),

    AGENCY(2, "代理"),

    JOIN(3, "加盟"),

    USER(1000, "用户"),

    ;

    /**
     * 值
     */
    private final Integer value;

    /**
     * 名称
     */
    private final String name;

    /**
     * 获取枚举名称
     * @param value 枚举值
     * @return 名称
     */
    public static String getName(Integer value) {
        for (BusinessTypeEnum businessTypeEnum : values()) {
            if (businessTypeEnum.value.equals(value)) {
                return businessTypeEnum.name;
            }
        }
        return "";
    }

    /**
     * 获取枚举列表
     * @return 枚举列表
     */
    public static List<NameValue<Integer>> getList() {
        return Stream.of(values())
                .map(businessTypeEnum -> new NameValue<>(businessTypeEnum.getName(), businessTypeEnum.getValue()))
                .collect(Collectors.toList());
    }

    /**
     * 获取枚举映射
     */
    public static Map<Integer, String> getMap() {
        return Stream.of(values())
                .collect(Collectors.toMap(BusinessTypeEnum::getValue, BusinessTypeEnum::getName, (a, b) -> b));
    }

    /**
     * 获取枚举映射
     */
    public static Map<String, Integer> getNameMap() {
        return Stream.of(values())
                .collect(Collectors.toMap(BusinessTypeEnum::getName, BusinessTypeEnum::getValue, (a, b) -> b));
    }

}
